package com.foreknow.demo2;

/**
 * java中的操作符
 */
public class OperationDemo {
    public static void main(String[] args) {
//        int a = 5;
//        int b =2;
//        System.out.println(a + b);
//        System.out.println(a - b);
//        System.out.println(a * b);
//        System.out.println(a / b);
//        System.out.println(a % b);
//
//        byte c =1;
//        byte d =2;
//        int z =c + d;
//        System.out.println(z);
//
//        int x =12;
//        double y =3.14;
//
//        double zz = x + y;//表达式中的变量有int和double 最终的类型为double
//        System.out.println(zz);
//            int a =5;
//            int b =a++; //运算规则：先将a的值赋值给b，然后a自增加1
//            int b =++a;//运算规则：先将a自增加1，然后再将值赋值给b
//            System.out.println(b);
//            System.out.println(a);
//            int z =(a++)+(++a)+(a--)+(--a);
            //(a++)=4   a=6
            //(++a)=7   a=7
            //(a--)=7   a=6
            //(--a)=5   a=5
//            System.out.println(z);//24
//            System.out.println(a);//5

//        System.out.println("-------------------------");
//        int a =3;
//        int b =5;
//        System.out.println(b += a);//b=b+a
//        System.out.println(b -= a);
//        System.out.println(b *= a);
//        System.out.println(b /= a);
//        System.out.println(b %= a);//b=b%a

//        short s =35;
//        s=s+1; 报错//s+1被认为int类型，需要强制类型转换
//        s +=1;//会包含类型转换的功能

//        System.out.println("-----------比较运算-----------");
//        boolean isRight =(a == b);
//        System.out.println(a == b);
//        System.out.println(a >= b);
//        System.out.println(a <= b);
//        System.out.println(a != b);

        System.out.println("-----------逻辑运算-----------");

        int a =5;
        int b =3;
        int c =2;

        boolean x1 = (a > b) && (b > c);
        boolean x2 = (a > b) && (b < c);


        boolean x3 = (a > b) || (b > c);
        boolean x4 = (a > b) || (b < c);
        boolean x5 = (a < b) || (b < c);

        boolean x6 = !(a > b);
        System.out.println(x1);
        System.out.println(x2);
        System.out.println(x3);
        System.out.println(x4);
        System.out.println(x5);
        System.out.println(x6);

        int i =5;
        boolean x = (i++ > 5) && (++i < 6);//逻辑与也叫短路与
        System.out.println(x);
        System.out.println(i);

        System.out.println("----------------------三元运算符------------------------");
        //已知一个数，判断这个数是奇数还是偶数
        int ii =5;
        char cc = (ii % 2 ==0)?'是':'否';
        System.out.println(cc);
    }
}
